﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DOTNETGROUP.Entities;
using DOTNETGROUP.Data;

public partial class Chi_Tiet_Nhom_Dao_Tao : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Pager1.CurrentIndex = 1;
            HienThi_TinTuc(Pager1.CurrentIndex);
        }
    }

    /// <summary>
    /// Thuc hien hien thi danh sach tin tuc va phan trang
    /// </summary>
    /// <param name="pageNo"></param>
    protected void HienThi_TinTuc(int pageNo)
    {
        int totals = 0;
        LoaiKhoaHoc ent_LoaiKhoaHoc = DataRepository.LoaiKhoaHocProvider.GetById(Convert.ToInt32(Request.Params["Id"]));
        litTieuDe.Text = ent_LoaiKhoaHoc.TenLoaiKhoaHoc;
        lblLoaiTin.Text = ent_LoaiKhoaHoc.TenLoaiKhoaHoc;
        linkloaitin.NavigateUrl = "~/DaoTaoCatalog/" + GetTieuDe(ent_LoaiKhoaHoc.TenLoaiKhoaHoc) + "_" + ent_LoaiKhoaHoc.Id +
                                  ".aspx";
        if (ent_LoaiKhoaHoc != null)
        {
            string WhereClause = "IdLoaiKhoaHoc= " + ent_LoaiKhoaHoc.Id;
            TList<KhoaHoc> tlistKhoaHocs = DataRepository.KhoaHocProvider.GetPaged(WhereClause, "NgayCapNhat DESC", pageNo - 1, Pager1.PageSize,
                out totals);
            if (tlistKhoaHocs.Count > 0)
            {
                dtlDsTinTuc.DataSource = tlistKhoaHocs;
                dtlDsTinTuc.DataBind();

                // Hien thi tong so trang
                Pager1.ItemCount = tlistKhoaHocs.Count;
                if (tlistKhoaHocs.Count <= Pager1.PageSize)
                    Pager1.Visible = false;
                else
                    Pager1.Visible = true;
            }
        }
    }

    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndex;
        HienThi_TinTuc(currnetPageIndex);
    }

    /// <summary>
    /// Phuong thuc chuyen tieu de co dau thanh khong dau de dua vao link
    /// </summary>
    /// <param name="Char"></param>
    /// <returns></returns>
    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    /// <summary>
    /// Format cat chuoi
    /// </summary>
    /// <param name="str"></param>
    /// <param name="n"></param>
    /// <returns></returns>
    public string formatString(string str, int n)
    {
        string kq = "";

        if (str.Length > n)
            kq = str.Substring(0, n + 1) + "...";
        else
            kq = str;

        return kq;
    }
}